package com.touch.jgloo.core;
/**
 * JGLPoint represents a point in 3D space. This is used in most JGLOO/OWT objects.
 * @author Homicidal Monkey
 * @version 10.1.9
 * @since r419 * 
 * @see com/touch/Licence
 */
public class JGLPoint
{
	/**
	 * Coordinates of the point
	 * @since r461
	 */
	public float x, y, z;
	/**
	 * Constructs a JGLPoint with the coordinates (0,0,0)
	 * @since r461
	 */
	public JGLPoint(){}
	/**
	 * Constructs a JGLPoint with specified coordinates
	 * @param x X-Coordinate
	 * @param y Y-Coordinate
	 * @param z Z-Coordinate
	 * @since r461
	 */
	public JGLPoint(final float x, final float y, final float z)
	{
		//sets the location of the point
		this.setLocation(x, y, z);
	}
	/**
	 * Sets the location of the point
	 * @param x X-Position
	 * @param y Y-Position
	 * @param z Z-Position
	 * @since r461
	 */
	public void setLocation(final float x, final float y, final float z)
	{
		//set the x position
		this.x = x;
		//set the y position
		this.y = y;
		//set the z position
		this.z = z;
	}	
	/**
	 * Overrides the "String toString" method in Object to describe the JGLPoint.
	 * @returns String representing the JGLPoint
	 * @since r461
	 */
	public String toString()
	{
		//return a String describing the point
		return "(" + this.x + ", " + this.y + ", " + this.z + ")";
	}
	/**
	 * Gets the X-Position of the point
	 * @return float value of the X-Position
	 * @since r461
	 */
	public float getX()
	{
		//return the x position
		return this.x;
	}
	/**
	 * Gets the Y-Position of the point
	 * @return float value of the Y-Position
	 * @since r461
	 */
	public float getY()
	{
		//returns the y position
		return this.y;
	}
	/**
	 * Gets the Z-Position of the point
	 * @return float value of the Z-Position
	 * @since r461
	 */
	public float getZ()
	{
		//returns the z position
		return this.z;
	}
	/** 
	 * Calculates a point in between two points
	 * @param p1 First point
	 * @param p2 Second point
	 * @param weight A value [0, 1] that defines how to balance. 0.5 is average of the values.
	 * @return A Point in between two points.
	 * @since r461
	 */
	public static JGLPoint deltaPoint(final JGLPoint p1, final JGLPoint p2, final float weight)
	{
		//calculate the difference in x		
		final float dX = (p1.x - p2.x) * weight;
		//calculate the difference in y
		final float dY = (p1.y - p2.y) * weight;
		//calculate the difference in z
		final float dZ = (p1.z - p2.z) * weight;
		
		//return the new point
		return new JGLPoint(dX, dY, dZ);
	}
}
